home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickTime / Programming Stuff / Documentation / develop articles / develop Issue 14 / Derived Media Handlers code / MyMediaComponent / MyMediaComponent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-25  |  6.7 KB  |  207 lines  |  [TEXT/KAHL]

  1. //--------------------------------------------------------------------------
  2. //
  3. //        MyMediaComponent.
  4. //            by John Wang
  5. //
  6. //        Description:    Sample Derived Media Component.
  7. //
  8. //        Version:    1.0        02/25/93    Based on MyComponent shell.
  9. //
  10. //--------------------------------------------------------------------------
  11.  
  12. //
  13. //    #includes
  14. //
  15.  
  16. #include    <Components.h>
  17. #include    <MediaHandlers.h>
  18. #include    "MyMediaComponent.h"
  19. #include    "MyMediaComponentRoutines.h"
  20. #include    "MyMemory.h"
  21. #include    "MyUtilities.h"
  22.  
  23. //--------------------------------------------------------------------------
  24.  
  25. //    Component entry point.
  26.  
  27. pascal ComponentResult main(ComponentParameters *params, PrivateGlobals **storage)
  28. {
  29.     switch (params->what) {
  30.         case kComponentOpenSelect:
  31.             return CallComponentFunction(params, (ComponentFunction) MyOpen);
  32.         case kComponentCloseSelect:
  33.             return CallComponentFunctionWithStorage((char **) storage, params,
  34.                     (ComponentFunction) MyClose);
  35.         case kComponentCanDoSelect:
  36.             return CallComponentFunction(params, (ComponentFunction) MyCanDo);
  37.         case kComponentVersionSelect: 
  38.             return CallComponentFunction(params, (ComponentFunction) MyVersion);
  39.         case kComponentRegisterSelect: 
  40.             return CallComponentFunctionWithStorage((char **) storage, params,
  41.                     (ComponentFunction) MyRegister);
  42.         case kMediaInitializeSelect:    
  43.             return CallComponentFunctionWithStorage((char **) storage, params,
  44.                     (ComponentFunction) MyMediaInitialize);                        
  45.         case kMediaIdleSelect:    
  46.             return CallComponentFunctionWithStorage((char **) storage, params,
  47.                     (ComponentFunction) MyMediaIdle);
  48.         case kMediaSetActiveSelect:
  49.             return CallComponentFunctionWithStorage((char **) storage, params,
  50.                     (ComponentFunction) MyMediaSetActive);
  51.         case kMediaSetRateSelect:
  52.             return CallComponentFunctionWithStorage((char **) storage, params,
  53.                     (ComponentFunction) MyMediaSetRate);
  54.         case kMediaTrackEditedSelect:
  55.             return CallComponentFunctionWithStorage((char **) storage, params,
  56.                     (ComponentFunction) MyMediaTrackEdited);
  57.         case kMediaSetGWorldSelect:
  58.             return CallComponentFunctionWithStorage((char **) storage, params,
  59.                     (ComponentFunction) MyMediaSetGWorld);
  60.         case kMediaSetDimensionsSelect:
  61.             return CallComponentFunctionWithStorage((char **) storage, params,
  62.                     (ComponentFunction) MyMediaSetDimensions);
  63.         case kMediaSetMatrixSelect:
  64.             return CallComponentFunctionWithStorage((char **) storage, params,
  65.                     (ComponentFunction) MyMediaSetMatrix);
  66.         case kMediaSampleDescriptionChangedSelect:
  67.             return CallComponentFunctionWithStorage((char **) storage, params,
  68.                     (ComponentFunction) MyMediaSampleDescriptionChanged);
  69.  
  70.         default:
  71.             if ((**storage).delegate) {
  72.                 //    If base media handler is targeted, then delegate all unimplemented
  73.                 //    calls to the base media handler.
  74.                 long    ret;
  75.                 
  76.                 ret = DelegateComponentCall(params, (**storage).delegate);
  77.                 if (DEBUGME && (params->what > 0x500) && (params->what < 0x5ff)) {
  78.                     //    Show all delegation to media handler
  79.                     Str255    myStr;
  80.                     
  81.                     BlockMove("\PDelegating selector: 0x      Return value:              ", myStr, 66);
  82.                     HexToString(params->what, (char *) &myStr[24]);
  83.                     LongToString(ret, (char *) &myStr[44]);
  84.                     DebugStr(myStr);
  85.                 }
  86.                 return(ret);
  87.             } else {
  88.                 //    If base media handler has not been targeted, then return paramErr.
  89.                 return(paramErr);
  90.             }
  91.     }
  92. }
  93.  
  94. //--------------------------------------------------------------------------
  95.  
  96. //    Required component calls.
  97.  
  98. pascal ComponentResult MyOpen(ComponentInstance self)
  99. {
  100.     PrivateGlobals         **storage;
  101.     ComponentInstance    myComp;
  102.         
  103.     if (DEBUGME == 1)
  104.         DebugStr("\PIn MyOpen()");
  105.  
  106.     //    Open base media handler component and target it.
  107.     if ((myComp = OpenDefaultComponent(MediaHandlerType, BaseMediaType)) == nil) {
  108.         return(componentNotCaptured);
  109.     }
  110.     ComponentSetTarget(myComp, self);
  111.  
  112.     //    Create private globals and initialize private variables.
  113.     if ((storage=(PrivateGlobals **)MyNewHandleClear(sizeof(PrivateGlobals))) == nil )     {
  114.         return(memFullErr);
  115.     }
  116.     SetComponentInstanceStorage(self, (Handle) storage);
  117.     (**storage).delegate = myComp;
  118.     (**storage).self = self;
  119.  
  120.     //    This component does not use shared globals.  Therefore, we don't use the refcon.
  121.     return(noErr);
  122. }
  123.  
  124. pascal ComponentResult MyClose(PrivateGlobals **storage, ComponentInstance self)
  125. {
  126.     if (DEBUGME == 1)
  127.         DebugStr("\PIn MyClose()");
  128.  
  129.     //    If storage has been allocated, then close base media handler component instance.
  130.     if (storage) {
  131.         if ((**storage).delegate) {
  132.             CloseComponent((**storage).delegate);
  133.             (**storage).delegate = nil;
  134.         }
  135.     }
  136.     
  137.     //    Dispose of private variables created by the open routine.  Since MyClose may called
  138.     //    even though MyOpen failed, we want to make sure that the handle is allocated before
  139.     //    disposing of it.  MyDiposeHandle does just that.  It doesn't dispose of the handle if
  140.     //    it is nil.  If it is not nil, it disposes of it, then sets the handle to nil.
  141.     MyDisposeHandle((Handle *) &storage);
  142.  
  143.     return(noErr);
  144. }
  145.  
  146. pascal ComponentResult MyCanDo(short selector)
  147. {    
  148.     if (DEBUGME == 1)
  149.         DebugStr("\PIn MyCanDo()");
  150.     
  151.     switch (selector) {
  152.         //    Required component calls.
  153.         case kComponentOpenSelect:
  154.         case kComponentCloseSelect:
  155.         case kComponentCanDoSelect:
  156.         case kComponentVersionSelect: 
  157.         case kComponentRegisterSelect: 
  158.  
  159.         //    MyComponent specific calls.
  160.         case kMediaInitializeSelect:    
  161.         case kMediaIdleSelect:    
  162.         case kMediaSetActiveSelect:
  163.         case kMediaSetRateSelect:
  164.         case kMediaTrackEditedSelect:
  165.         case kMediaSetGWorldSelect:
  166.         case kMediaSetDimensionsSelect:
  167.         case kMediaSetMatrixSelect:
  168.         case kMediaSampleDescriptionChangedSelect:
  169.             return(true);
  170.  
  171.         //    Otherwise, return FALSE.
  172.         default:
  173.             if (DEBUGME) {
  174.                 Str255    myStr;
  175.                 
  176.                 BlockMove("\PCan't do: 0x            ", myStr, 25);
  177.                 HexToString(selector, (char *) &myStr[13]);
  178.                 DebugStr(myStr);
  179.             }
  180.             return (false);
  181.     }
  182. }
  183.  
  184. pascal ComponentResult MyVersion()
  185. {
  186.     if (DEBUGME == 1)
  187.         DebugStr("\PIn MyVersion()");
  188.  
  189.     return ((kMyComponentSpec<<16) || (kMyComponentVersion));
  190. }
  191.  
  192. pascal ComponentResult MyRegister(PrivateGlobals **storage)
  193. {
  194.     if (DEBUGME == 1)
  195.         DebugStr("\PIn MyRegister()");
  196.  
  197.     //    We will actually never get this far because the MyOpen routine would have returned an
  198.     //    error which would have already notified the Component Manager not to register us.
  199.     //    We still put the code here since the Component Manager expects us to implement this
  200.     //    routine since we set the wantsRegisterMessage flag.  If we didn't set the flag,
  201.     //    our component would never get opened during registration and we would always get
  202.     //    registered even if the base media handler was unavailable.  i.e. under QuickTime 1.0.
  203.     if (storage)
  204.         return (FALSE);    //    Globals properly set up meaning that base media handler targeted ok
  205.     else
  206.         return (TRUE);    //    Globals not properly set up meaning we don't register
  207. }